var timer = setInterval(CheckState,2000);
var ajaxStarted= false;
var progIndex = 1;

function CheckState()
{
  if(!ajaxStarted)
  {
    ajaxStarted=true;
   $.post("ajax/checkFullScan.php",{"prog":progIndex}).done(function(data)
   {
     if(data==="true")
     {
       $("#progressTable tbody tr:nth-of-type("+progIndex+") td:nth-last-of-type(1)").empty().append($('<img>')
               .attr({"src":"../design/pictures/tick.png",
                      "width":"16px",
                      "alt":"Fertig"}));
      $("#progressTable tbody tr:nth-of-type("+(progIndex+1)+") td:nth-last-of-type(1)").empty().append($('<img>')
              .attr({"src":"../design/pictures/loading.gif",
                     "width":"16px",
                     "alt":"loading"}));
                   
       if(progIndex === 5)
         clearInterval(timer);
       progIndex++;
     }
     else if(data==="error")
     {
       $("#progressTable tbody tr:nth-of-type("+progIndex+") td:nth-last-of-type(1)").empty().append($('<img>')
               .attr({"src":"../design/pictures/error.png",
                      "width":"16px",
                      "alt":"Error"}));
       clearInterval(timer);
     }
     else if(data==="warning")
     {
       $("#progressTable tbody tr:nth-of-type("+progIndex+") td:nth-last-of-type(1)").empty().append($('<img>')
               .attr({"src":"../design/pictures/warning.png",
                      "width":"16px",
                      "alt":"Fertig"}));
                    
       if(progIndex === 5)
          clearInterval(timer);
       else
       {
          $("#progressTable tbody tr:nth-of-type("+(progIndex+1)+") td:nth-last-of-type(1)").empty().append($('<img>')
                  .attr({"src":"../design/pictures/loading.gif",
                         "width":"16px",
                         "alt":"loading"}));
       }
       progIndex++;
     }
     
     ajaxStarted=false;
   });  
  }
}

